//
//  ByNoticeNumberCell.m
//  caipiao_ios
//
//  Created by mc on 2018/7/27.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByNoticeNumberCell.h"
#import "ByNoticeTitleView.h"
#import "ByNoticeSuperResultVIew.h"
#import "ByNoticeCirclesView.h"

@implementation ByNoticeNumberCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByNoticeNumberCell";
    ByNoticeNumberCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
        
    }
    return self;
}


- (void)initViews{
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.top.equalTo(self.contentView).offset(0);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
    backgroundView.layer.cornerRadius = 10;
    backgroundView.backgroundColor = [UIColor whiteColor];
    
    ByNoticeTitleView *titleView = [[ByNoticeTitleView alloc] init];
    [backgroundView addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(backgroundView).offset(15);
        make.height.mas_equalTo(@15);
    }];
    self.titleView = titleView;
    if (_netModel.category_id.integerValue == 1001) {
        titleView.titleLabel.text = @"双色球";
    }else if (_netModel.category_id.integerValue == 2001){
        titleView.titleLabel.text = @"大乐透";
    }
    titleView.timeLabel.text = [NSString stringWithFormat:@"第%@期 %@", _netModel.number ,_netModel.open_time];
    
    
    ByNoticeCirclesView *circlesView = [[ByNoticeCirclesView alloc] init];
    [backgroundView addSubview:circlesView];
    [circlesView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.top.equalTo(titleView.mas_bottom).offset(5);
        make.right.equalTo(backgroundView).offset(-40);
        make.height.mas_equalTo(@60);
    }];
    circlesView.itemsAry = _netModel.numArray;
    
    UIView *grayView = [[UIView alloc] init];
    [backgroundView addSubview:grayView];
    [grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(circlesView.mas_bottom).offset(0);
        make.bottom.equalTo(backgroundView).offset(0);
    }];
    grayView.backgroundColor = rgba(251, 251, 251, 1);
    
    
    
    ByNoticeSuperResultVIew *resultView = [[ByNoticeSuperResultVIew alloc] init];
    [backgroundView addSubview:resultView];
    [resultView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(15);
        make.bottom.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@60);
    }];
    resultView.netModel = _netModel;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(11);
        make.right.equalTo(backgroundView).offset(0);
        make.bottom.equalTo(resultView.mas_top).offset(-10);
        make.height.mas_equalTo(@15);
    }];
    titleLabel.font = FONT(14);
    titleLabel.textColor = [UIColor brownColor];
    titleLabel.text = @"开奖结果";
    
    
    UIImageView *arrowView = [[UIImageView alloc] init];
    [backgroundView addSubview:arrowView];
    [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-15);
        make.top.equalTo(backgroundView).offset(37);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    arrowView.image = [UIImage imageNamed:@"youjiantou1111"];
    
    ByDottedLineView *line = [[ByDottedLineView alloc] init];
    line.direction = DottedLineViewDirectionHorizontalFromRight;
    line.lineColor = BY_LINE_COLOR;
    line.lengthPattern = @[@4, @3];
    [backgroundView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(circlesView.mas_bottom).offset(0);
        make.height.mas_equalTo(@1);
    }];
    
    
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    [self initViews];
}
@end
